import Vue from 'vue'

function drag(el) {
    el.style.position = 'absolute'
    var startX, startY // 记录点击的初始位置
    el.ontouchstart = function(e) {
        startX = e.touches[0].pageX - el.offsetLeft
        startY = e.touches[0].pageY - el.offsetTop
        el.ontouchmove = function(em) {
            el.style.left = em.touches[0].pageX - startX + 'px'
            el.style.top = em.touches[0].pageY - startY + 'px'
        }
    }
    el.ontouchend = function() {
        document.ontouchmove = null
    }

}


Vue.directive('drag', {
    bind(el) {
        drag(el)
    }
})